using System;

using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using server.TypingServiceDataSetTableAdapters;  
namespace server
{
    public class TypingServiceDataUtil
    {
        /// <summary>
        /// Insert Author row and return the new AuthorId
        /// </summary>
        /// <returns></returns>
        public decimal InsertAuthor(string Email, string FirstName, string LastName, string Address, string City, string State, string Country, string ZipCode, string Phone, string Fax, string Church, string RecommendBy)
        {
            TypingServiceDataSet.AuthorDataTable table = new TypingServiceDataSet.AuthorDataTable();
            table.AddAuthorRow(Email, FirstName, LastName, Address, City, State, Country, ZipCode, Phone, Fax, Church, RecommendBy);
            AuthorTableAdapter adapter = new AuthorTableAdapter();
            int result = adapter.Update(table);
            if (result == 1)
            {
                if (table.Rows.Count == 1)
                {
                    return (decimal)table.Rows[0][0];
                }
            }
            return -1;
        }
        public bool UpdateAuthor(string Email, string FirstName, string LastName, string Address, string City, string State, string Country, string ZipCode, string Phone, string Fax, string Church, string RecommendBy, decimal AuthorId)
        {
            AuthorTableAdapter adapter = new AuthorTableAdapter();
            int result= adapter.Update (Email, FirstName, LastName, Address, City, State, Country, ZipCode, Phone, Fax, Church, RecommendBy, AuthorId, AuthorId);
            return result == 1;
        }

        public decimal InsertWriting(decimal AuthorID, string Title, int CategoryID, int SourcePostID, int ResultPostID, DateTime ReceiveDate, string Desc1, string Desc2, string Desc3)
        {
            TypingServiceDataSet.WritingDataTable table = new TypingServiceDataSet.WritingDataTable();
          
            TypingServiceDataSet.WritingRow rowWritingRow = ((TypingServiceDataSet.WritingRow)(table.NewRow()));
            rowWritingRow.ItemArray = new object[] {
                        null,
                        AuthorID,
                        Title,
                        CategoryID,
                        SourcePostID,
                        ResultPostID,
                        ReceiveDate,
                        Desc1,
                        Desc2,
                        Desc3};
            table.AddWritingRow(rowWritingRow);
            
            WritingTableAdapter adapter = new WritingTableAdapter();
            int result = adapter.Update(table);
            if (result == 1)
            {
                if (table.Rows.Count == 1)
                {
                    return (decimal)table.Rows[0][0];
                }
            }
            return -1;
        }
        public bool UpdateWriting(int AuthorID, string Title, int CategoryID, int SourcePostID, int ResultPostID, DateTime ReceiveDate, string Desc1, string Desc2, string Desc3,decimal WritingID)
        {
            WritingTableAdapter adapter = new WritingTableAdapter();
            int result = adapter.Update(AuthorID, Title, CategoryID, SourcePostID, ResultPostID, ReceiveDate, Desc1, Desc2, Desc3, WritingID, WritingID);
            return result == 1;
        }
    }
}
